<?
 include("conn.php");
 if($_GET[out]){
 setcookie("cookie","out");
  echo "<script language=\"javascript\">location.href='login.php';</script>";
 }



 $username= str_replace(" ","",$_POST[username]);
    $sql="select * from d_user where `username` = '$username'";
 $query=mysql_query($sql);
 //echo $query;
$us=is_array($row=mysql_fetch_array($query));
    $ps= $us ? md5($_POST[pw].ALL_PS)== $row[password] : FALSE;
//echo $row[username];  mysql_fetch_assoc只显示字母键值的下标        
//print_r ($row);

//echo  md5(123456);

	
 if($ps)
 {

	 setcookie("cookie","ok");
	 echo "<script language=\"javascript\">location.href='login.php';</script>";//重新载入当前页面跳出页面从新打开新页面
 
 }

 include("head.php");
 if($_COOKIE['cookie']!='ok'){
?>
<SCRIPT language=javascript>
function Checklogin()
{
	if (myform.username.value=="")
	{
		alert("请输入用户名");
		myform.id.focus();   //鼠标聚焦到user文本框
		return false;
	}
	if (myform.pw.value=="")
	{
		alert("密码不能为空");
		myform.pw.focus();
        return false;
	}
}
</SCRIPT>
 <form action="" method="post" name="myform" onsubmit="return Checklogin();">
    ID:<input type="text"name="username"/><br>
    PW:<input type="password"name="pw"/>
 <input type="submit" name="submit" value="登录"/>
</form>
<?
 }else{//?就是代表当前那个url后加？
?>
<a href='?out=login'>退出</a>
<?
}//这里的？out和上面的$_GET[out]是对应的。获得的值非零就响应
?>